package com.group56.view.coachend.coach_info_module;

import com.group56.CoachApp;
import com.group56.factory.AppCMFactory;
import com.group56.factory.CoachAppCMFactory;
import com.group56.utils.FXMLSrcMenu;
import com.group56.view.FrameworkController;
import com.group56.view.ViewController;
import com.group56.viewmodel.CoachInfoVM;
import javafx.beans.property.SimpleObjectProperty;
import javafx.event.ActionEvent;
import javafx.scene.Parent;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;

public class CoachInfoController implements ViewController {
    public AnchorPane view;
    public ImageView pic;
    public TextField nameText;
    public TextField sexText;
    public TextField teleText;
    public TextField detailText;
    public Button saveButton;
    private CoachInfoVM coachInfoVM = CoachInfoVM.getInstance(CoachApp.coachId);

    public void initialize(){
        inject();
        bind();
    }
    @Override
    public void inject() {
        pic.setImage(new Image(coachInfoVM.getPicUrl()));
        nameText.setText(coachInfoVM.getName());
        sexText.setText(coachInfoVM.getSex());
        teleText.setText(coachInfoVM.getTele());
        detailText.setText(coachInfoVM.getDetail());
    }

    @Override
    public void bind() {
        pic.imageProperty().bindBidirectional(new SimpleObjectProperty<Image>(new Image(coachInfoVM.getPicUrl())));
        nameText.textProperty().bindBidirectional(coachInfoVM.nameProperty());
        sexText.textProperty().bindBidirectional(coachInfoVM.sexProperty());
        teleText.textProperty().bindBidirectional(coachInfoVM.teleProperty());
        detailText.textProperty().bindBidirectional(coachInfoVM.detailProperty());
    }

    @Override
    public void registerToMediator() {

    }

    @Override
    public Parent getView() {
        return view;
    }

    public void onClickBtn(ActionEvent actionEvent) {
        coachInfoVM.updateToModel();
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setHeaderText("successful modify information");
        alert.show();
        coachInfoVM.updateFromModel();
    }
}
